#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <random>
#include <unordered_map>
#include "graph.h"
#define mems(x, v) memset(x, v, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef long double wisdom;

vector <int> G[205];
struct Edge {int now, nxt, w;} e[114514]; int head[205], cur, n;
void add(int u, int v, int w) {e[++cur].now = v, e[cur].nxt = head[u], e[cur].w = w, head[u] = cur;}
void recall(int lst = 0, int t = 0) {Move(!lst ? LastRoad() : lst, !t ? Color() : t);}

mt19937 rdqwq(19260817);
inline int rnd(int l, int r) {return ((int)rdqwq() % (r - l + 1) + (r - l + 1)) % (r - l + 1) + l;}

void fndtree(int u) {
	int deg = NumberOfRoads();
	for (int i = 1; i <= deg; i++) {
		Move(i, 2); int lst = LastRoad();
		if (Color() == 1) n++, add(u, n, i), add(n, u, LastRoad()), fndtree(n);
		recall(lst);
	}
}
int rt, redo[120], top, viscnt[205], perm[120][205], P[205][205]; ull H[205];
void cover(int u, int fa) {for (int i = head[u], v; i; i = e[i].nxt) if ((v = e[i].now) != fa) {Move(e[i].w, rnd(1, 3)); int lst = LastRoad(); cover(v, u), recall(lst);}}
void check(int u) {int deg = NumberOfRoads(); for (int i = 1; i <= deg; i++) {Move(i, Color()); if (Color() == 3) {G[rt].push_back(u); recall(); break;} recall();}}
inline ull Hash() {
	int deg = 0; ull h = Color(); mems(viscnt, 0);

	deg = NumberOfRoads(); for (int w = 1; w <= min(deg, 5); w++) Move(P[deg][w], Color()), h = h * 647 + (NumberOfRoads() * 3 + Color()), recall();
	Move(perm[++viscnt[NumberOfRoads()]][NumberOfRoads()], Color()), redo[++top] = LastRoad();
	deg = NumberOfRoads(); for (int w = 1; w <= min(deg, 5); w++) Move(P[deg][w], Color()), h = h * 647 + (NumberOfRoads() * 3 + Color()), recall();
	Move(perm[++viscnt[NumberOfRoads()]][NumberOfRoads()], Color()), redo[++top] = LastRoad();
	deg = NumberOfRoads(); for (int w = 1; w <= min(deg, 5); w++) Move(P[deg][w], Color()), h = h * 647 + (NumberOfRoads() * 3 + Color()), recall();

	while (top) recall(redo[top--]); return h;
}
unordered_map <ull, bool> sb;
void gethsh(int u, int fa) {H[u] = Hash(); for (int i = head[u], v; i; i = e[i].nxt) if ((v = e[i].now) != fa) {Move(e[i].w, Color()); int lst = LastRoad(); gethsh(v, u), recall(lst);}}
void dfs(int u, int fa) {
	int deg = NumberOfRoads();
	for (int w = 1; w <= deg; w++) {
		Move(w, Color()); int lst = LastRoad(); ull h = Hash();
		vector <int> nde; for (int i = 1; i <= n; i++) if (H[i] == h) nde.push_back(i);
		if (nde.size() != 1) fprintf(stderr, "WARNING SIZE = %d\n", (int)nde.size());
		for (int x : nde) G[u].push_back(x); recall(lst);
	}
	for (int i = head[u], v; i; i = e[i].nxt) if ((v = e[i].now) != fa) {Move(e[i].w, Color()); int lst = LastRoad(); dfs(v, u), recall(lst);}
}
namespace GETANS {
	int ans[205], dis[205];
	void bfs(int s) {
		queue <int> q; mems(dis, -1), q.push(s), dis[s] = 0;
		while (!q.empty()) {int u = q.front(); q.pop(); ans[dis[u]]++; for (int v : G[u]) if (!~dis[v]) dis[v] = dis[u] + 1, q.push(v);}
	}
	void output(int R) {
		for (int i = 1; i <= n; i++) bfs(i);
		for (int i = 1; i <= R; i++) Answer(i, ans[i] >> 1);
	}
}
void Inspect(int R) {
	for (int i = 1; i <= 100; i++) for (int j = 1; j <= 200; j++) perm[i][j] = rnd(1, j);
	for (int i = 1; i <= 200; i++) {for (int j = 1; j <= i; j++) P[i][j] = j; shuffle(P[i] + 1, P[i] + i + 1, rdqwq);}
	fndtree(++n), cover(1, 0), gethsh(1, 0), dfs(1, 0), GETANS::output(R);
}
